package top.truism.auth.util;

import top.truism.auth.annotation.Required;
import top.truism.auth.enums.UserLevel;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class AnnotationUtil {

  public AnnotationUtil() {
  }

  public static UserLevel findRequired(Method method) {
    Annotation[] annotations = method.getAnnotations();
    for (int i = 0; i < annotations.length; i++) {
      Class<? extends Annotation> clz = annotations[i].annotationType();
      Required required = clz.getAnnotation(Required.class);
      if (required != null) {
        return required.level();
      }
    }
    return UserLevel.Tourist;
  }

}
